package com.example.nna.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.nna.voz.containEmo;

public class loadAssets{
	private Bitmap Avatar;
	private Bitmap IconForumNew;
	private Bitmap IconForumOld;
	private Bitmap IconThreadNew;
	private Bitmap IconThreadHotNew;
	private Bitmap IconThread;
	private Bitmap IconThreadHot;
	private Bitmap IconThreadLock;
	private Bitmap IconVoz;
	InputStream is;
	AssetManager am;
	Context mContext;
	public loadAssets(Context mContext){
		this.mContext = mContext;
		am = mContext.getAssets();
		IconForumNew = null;
		IconForumOld = null;
		IconThread = null;
		IconThreadLock = null;
		IconThreadHot = null;
		IconThreadHotNew = null;
		IconThreadNew = null;
		Avatar = null;
		IconVoz = null;
	}
	public Bitmap quote(){
		try {
			is = am.open("reply/quote.gif");
			Bitmap emo = BitmapFactory.decodeStream(is);
			is.close();
			return emo;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Voz();
		}
	}
	public Bitmap quickreplyoff(){
		try {
			is = am.open("reply/quickreply_off.gif");
			Bitmap emo = BitmapFactory.decodeStream(is);
			is.close();
			return emo;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Voz();
		}
	}
	public Bitmap quickreplyon(){
		try {
			is = am.open("reply/quickreply_on.gif");
			Bitmap emo = BitmapFactory.decodeStream(is);
			is.close();
			return emo;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Voz();
		}
	}
	public Bitmap multiquote(){
		try {
			is = am.open("reply/multiquote.gif");
			Bitmap emo = BitmapFactory.decodeStream(is);
			is.close();
			return emo;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Voz();
		}
	}
	public Bitmap Emo(String str){
		
		try {
			String temp = str.substring(0,str.length()-4);
			is = am.open("emo/"+temp+".png");
			if(is == null ) is = am.open("emo/"+temp+".gif");
			Bitmap emo = BitmapFactory.decodeStream(is);
			is.close();
			return emo;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Voz();
		}
	}
	public Bitmap EmoAnimated(String str){
		
		try {
			String temp = str.substring(0,str.length()-4);
			is = am.open("animated/"+temp+".gif");
			Bitmap emo = BitmapFactory.decodeStream(is);
			is.close();
			return emo;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Voz();
		}
	}
	public ArrayList<containEmo> Emo2(){
		ArrayList<containEmo> listEmo = new ArrayList<containEmo>();
		try {
			String list[] = am.list("emo");
			String temp;
			Bitmap emo;
			for(int i=0;i<list.length;i=i+1){
				temp = list[i].substring(0,list[i].length()-4);
				is = am.open("emo/"+temp+".png");
				emo = BitmapFactory.decodeStream(is);
				if(temp.equals("embarrassed")) 			temp = ":\">";
				else if(temp.equals("nosebleed"))		temp = "chaymau";
				else if(temp.equals("feel_good"))		temp = "sogood";
				else if(temp.equals("sexy_girl"))		temp = "sexy";
				else if(temp.equals("look_down"))		temp = "look_down";
				else if(temp.equals("beat_brick"))		temp = "brick";
				else if(temp.equals("cry"))				temp = ":((";
				else if(temp.equals("beat_plaster"))	temp = ":-s";
				else if(temp.equals("confuse"))			temp = "chaymau";
				else if(temp.equals("big_smile"))		temp = ":D";
				else if(temp.equals("brick"))			temp = "gach";
				else if(temp.equals("burn_joss_stick"))	temp = "stick";
				else if(temp.equals("bad_smell"))		temp = "badsmell";
				else if(temp.equals("cool"))			temp = "kool";
				else if(temp.equals("after_boom"))			temp = "aboom";
				else if(temp.equals("beat_shot"))			temp = "shot";
				else if(temp.equals("sweet_kiss"))			temp = ":*";
				else if(temp.equals("beat_shot"))			temp = "shot";
				else if(temp.equals("smile"))			temp = ":)";
				else if(temp.equals("still_dreaming"))			temp = "dreaming";
				else if(temp.equals("beat_shot"))			temp = "shot";
				else if(temp.equals("beat_shot"))			temp = "shot";
				
				listEmo.add(new containEmo(emo, ":"+temp+":"));
				is.close();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return listEmo;
	}
	
	public Bitmap Voz(){
		if(IconVoz == null){
			try {
				is = am.open("google.png");
				IconVoz = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconVoz;
	}
	public Bitmap android(){
		if(Avatar == null){
			try {
				is = am.open("google.png");
				Avatar = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return Avatar;
	}
	public Bitmap IconForumNew(){
		if(IconForumNew == null){
			try {
				is = am.open("forum_new.gif");
				IconForumNew = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconForumNew;
	}
	public Bitmap IconForumOld(){
		if(IconForumOld == null){
			try {
				is = am.open("forum_old.gif");
				IconForumOld = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconForumOld;
	}
	public Bitmap IconThread(){
		if(IconThread == null){
			try {
				is = am.open("thread.gif");
				IconThread = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconThread;
	}
	public Bitmap IconThreadNew(){
		if(IconThreadNew == null){
			try {
				is = am.open("thread_new.gif");
				IconThreadNew = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconThreadNew;
	}
	public Bitmap IconThreadHotNew(){
		if(IconThreadHotNew == null){
			try {
				is = am.open("thread_hot_new.gif");
				IconThreadHotNew = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconThreadHotNew;
	}
	public Bitmap IconThreadHot(){
		if(IconThreadHot == null){
			try {
				is = am.open("thread_hot.gif");
				IconThreadHot = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconThreadHot;
	}
	public Bitmap IconThreadLock(){
		if(IconThreadLock == null){
			try {
				is = am.open("thread_lock.gif");
				IconThreadLock = BitmapFactory.decodeStream(is);
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return IconThreadLock;
	}
	public Bitmap IconThreadHotLock(){
		Bitmap bitmap = Voz();;
		try {
			is = am.open("thread_hot_lock.gif");
			bitmap = BitmapFactory.decodeStream(is);
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return bitmap;
	}
	public String loadString(){
		String t= null;
		int i=0;
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		try {
			InputStream is = am.open("aaa.txt");
		    while (i != -1){
		    	i = is.read();
		    	byteArrayOutputStream.write(i);
		     }
		    t = byteArrayOutputStream.toString("UTF-8");
		    is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return t;
	
	}
	
}
